package com.vertx.core;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @version v1.0
 * @Description: Verticle helloword
 * @Author: TongRui乀
 * @Date: 2021/5/7 12:01 下午
 */
public class HelloVerticle extends AbstractVerticle {

    @Override
    public void init(Vertx vertx, Context context) {
        super.init(vertx, context);
        System.out.println("initing......");
        System.out.println(context.config().getString("name"));
    }

    @Override
    public void start() throws Exception {

        vertx.setPeriodic(1000, h->{
            System.out.println("current time" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        });
    }

    public static void main(String[] args) {

        var vertx = Vertx.vertx();

//        vertx.deployVerticle(new HelloVerticle());

        DeploymentOptions options = new DeploymentOptions();

        JsonObject config = new JsonObject();

        config.put("name", "jams");

        options.setConfig(config);

        options.setInstances(2);

        vertx.deployVerticle("com.vertx.core.HelloVerticle", options, h->{
            if (h.succeeded()) {
                System.out.println("deploy success" + h.result());
            }
        });
    }
}
